package com.baidu.service;

import com.baidu.mapper.IssueMapper;
import com.baidu.pojo.Issue;
import com.baidu.utils.PageResult;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author ZYH
 * @version 1.0
 * @description:TODO
 * @date 2022/1/7 14:46
 */
@Service
public class IssueServiceImpl extends ServiceImpl<IssueMapper, Issue> implements IssueService{

    @Autowired
    private IssueMapper issueMapper;

    @Override
    public List<Issue> getList() {
        return issueMapper.selectList(null);
    }

    @Override
    public PageResult search(Integer pageNum, Integer pageSize, Map search) {
        Page page = new Page<>(pageNum, pageSize);
        String title = (String)search.get("title");
        QueryWrapper<Issue> queryWrapper = new QueryWrapper<>();
        if(!StringUtils.isBlank(title)){
            queryWrapper.lambda().eq(Issue::getTitle,title);
        }
        Page page1 = issueMapper.selectPage(page, queryWrapper);
        return new PageResult((int)page1.getTotal(),page1.getRecords());
    }

    @Override
    public void deleteIssue(Integer Issueid) {
         issueMapper.deleteById(Issueid);
    }

    @Override
    public void saveIssue(Issue issue) {
        issueMapper.insert(issue);

    }

    @Override
    public int updateIssue(Issue issue) {
        int i = issueMapper.updateById(issue);
        return i;
    }
}
